package com.sto.stoapp.activity.administrator;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.db.StoFilePreference;
import com.sto.stoapp.listener.StoOnClickListener;
import com.sto.stoapp.widget.StoHomeActivity;

public class AdminServerPortActivity extends StoHomeActivity {
	public static final String SERVER_INFO = "server_info";
	public static final String SERVER_PORT = "server_port";

	private int dataPort, upgradePort, orderPort;

	private Button dataPortBtn, upgradePortBtn, orderPortBtn;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.admin_server_port);
		this.setTitleBottom(R.string.admin_server_port,
				HomeBroadAction.ADMINISTRATOR_BROAD);
		initWidget();
		initListener();
	}

	private void initListener() {
		dataPortBtn.setOnClickListener(new StoOnClickListener(this) {

			@Override
			public void mHonClick(View view) {
				Intent intent = new Intent(AdminServerPortActivity.this,
						ServerPortDetailActivity.class);
				intent.putExtra(SERVER_INFO, R.string.data_port);
				intent.putExtra(SERVER_PORT, dataPort);
				startActivity(intent);
			}
		});

		upgradePortBtn.setOnClickListener(new StoOnClickListener(this) {

			@Override
			public void mHonClick(View view) {
				Intent intent = new Intent(AdminServerPortActivity.this,
						ServerPortDetailActivity.class);
				intent.putExtra(SERVER_INFO, R.string.upgrade_port);
				intent.putExtra(SERVER_PORT, upgradePort);
				startActivity(intent);
			}
		});

		orderPortBtn.setOnClickListener(new StoOnClickListener(this) {

			@Override
			public void mHonClick(View view) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(AdminServerPortActivity.this,
						ServerPortDetailActivity.class);
				intent.putExtra(SERVER_INFO, R.string.order_port);
				intent.putExtra(SERVER_PORT, orderPort);
				startActivity(intent);
			}
		});
	}

	@Override
	protected void onResume() {
		super.onResume();
		dataPort = StoFilePreference.getInstance(this).getDataServicePort();
		upgradePort = StoFilePreference.getInstance(this)
				.getUpgradeServicePort();
		orderPort = StoFilePreference.getInstance(this).getOrderPort();
		dataPortBtn.setText(getText(R.string.data_port).toString() + dataPort);
		upgradePortBtn.setText(getText(R.string.upgrade_port).toString()
				+ upgradePort);
		orderPortBtn.setText(getText(R.string.order_port).toString()
				+ orderPort);
	}

	private void initWidget() {
		dataPortBtn = (Button) findViewById(R.id.data_port);
		upgradePortBtn = (Button) findViewById(R.id.upgrade_port);
		orderPortBtn = (Button) findViewById(R.id.order_port);

	}
	

}
